//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.user;

import java.awt.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.gui.iconBar.IconBar;

public class UserGUI extends JInternalFrame {

    public UserGUI() {
        jContentPane = null;
        basicMenu = null;
        iconBar = null;
        jTabbedPane = null;
        mainPanel = null;
        lawPanel = null;
        userListLabelAndComboBox = null;
        mainPanel1 = null;
        lastnameLabelAndTextField = null;
        firstnameLabelAndTextField = null;
        addrLn1LabelAndTextField = null;
        addrLn2LabelAndTextField = null;
        cityLabelAndTextField = null;
        zipLabelAndTextField = null;
        telLabelAndTextField = null;
        faxLabelAndTextField = null;
        emailLabelAndTextField = null;
        loginPanel = null;
        celLabelAndTextField = null;
        loginLabelAndTextField = null;
        passwordLabelAndTextField = null;
        groupLabelAndComboBox = null;
        jobLabelAndTextField = null;
        numberConnectionLabelAndTextField = null;
        lastConnectionLabelAndTextField = null;
        expiryDateLabelAndDateComboBox = null;
        msgTextArea = null;
        lawTableViewer = null;
        jScrollPane = null;
        initialize();
    }

    private void initialize() {
        setPreferredSize(new Dimension(335, 139));
        setJMenuBar(getBasicMenu());
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/arrowRight18x18.png")));
        setTitle("UTILISATEURS");
        setSize(330, 408);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getIconBar(), "North");
            jContentPane.add(getMainPanel1(), "Center");
        }
        return jContentPane;
    }

    private BasicMenu getBasicMenu() {
        if (basicMenu == null) {
            basicMenu = new BasicMenu();
        }
        return basicMenu;
    }

    private IconBar getIconBar() {
        if (iconBar == null) {
            iconBar = new IconBar();
        }
        return iconBar;
    }

    private JTabbedPane getJTabbedPane() {
        if (jTabbedPane == null) {
            jTabbedPane = new JTabbedPane();
            jTabbedPane.addTab("Coordonn\351es", null, getMainPanel(), null);
            jTabbedPane.addTab("Login", null, getLoginPanel(), null);
            jTabbedPane.addTab("Droits", null, getLawPanel(), null);
        }
        return jTabbedPane;
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            FlowLayout flowLayout1 = new FlowLayout();
            mainPanel = new JPanel();
            mainPanel.setLayout(flowLayout1);
            flowLayout1.setVgap(1);
            mainPanel.add(getLastnameLabelAndTextField(), null);
            mainPanel.add(getFirstnameLabelAndTextField(), null);
            mainPanel.add(getAddrLn1LabelAndTextField(), null);
            mainPanel.add(getAddrLn2LabelAndTextField(), null);
            mainPanel.add(getCityLabelAndTextField(), null);
            mainPanel.add(getZipLabelAndTextField(), null);
            mainPanel.add(getTelLabelAndTextField(), null);
            mainPanel.add(getCelLabelAndTextField(), null);
            mainPanel.add(getFaxLabelAndTextField(), null);
            mainPanel.add(getEmailLabelAndTextField(), null);
        }
        return mainPanel;
    }

    private JPanel getLawPanel() {
        if (lawPanel == null) {
            lawPanel = new JPanel();
            lawPanel.setLayout(new BorderLayout());
            lawPanel.add(getLawTableViewer(), "Center");
        }
        return lawPanel;
    }

    private LabelAndComboBox getUserListLabelAndComboBox() {
        if (userListLabelAndComboBox == null) {
            userListLabelAndComboBox = new LabelAndComboBox();
            userListLabelAndComboBox.setLabel("Liste des utilisateurs");
            userListLabelAndComboBox.setToolTipText("Choisir un utilisateur");
        }
        return userListLabelAndComboBox;
    }

    private JPanel getMainPanel1() {
        if (mainPanel1 == null) {
            mainPanel1 = new JPanel();
            mainPanel1.setLayout(new BorderLayout());
            mainPanel1.add(getUserListLabelAndComboBox(), "North");
            mainPanel1.add(getJTabbedPane(), "Center");
        }
        return mainPanel1;
    }

    private LabelAndTextField getLastnameLabelAndTextField() {
        if (lastnameLabelAndTextField == null) {
            lastnameLabelAndTextField = new LabelAndTextField();
            lastnameLabelAndTextField.setLabel("Nom");
            lastnameLabelAndTextField.setVal("");
        }
        return lastnameLabelAndTextField;
    }

    private LabelAndTextField getFirstnameLabelAndTextField() {
        if (firstnameLabelAndTextField == null) {
            firstnameLabelAndTextField = new LabelAndTextField();
            firstnameLabelAndTextField.setLabel("Pr\351nom");
            firstnameLabelAndTextField.setVal("");
        }
        return firstnameLabelAndTextField;
    }

    private LabelAndTextField getAddrLn1LabelAndTextField() {
        if (addrLn1LabelAndTextField == null) {
            addrLn1LabelAndTextField = new LabelAndTextField();
            addrLn1LabelAndTextField.setLabel("Adresse");
            addrLn1LabelAndTextField.setVal("");
        }
        return addrLn1LabelAndTextField;
    }

    private LabelAndTextField getAddrLn2LabelAndTextField() {
        if (addrLn2LabelAndTextField == null) {
            addrLn2LabelAndTextField = new LabelAndTextField();
            addrLn2LabelAndTextField.setLabel("");
            addrLn2LabelAndTextField.setVal("");
        }
        return addrLn2LabelAndTextField;
    }

    private LabelAndTextField getCityLabelAndTextField() {
        if (cityLabelAndTextField == null) {
            cityLabelAndTextField = new LabelAndTextField();
            cityLabelAndTextField.setLabel("Ville");
            cityLabelAndTextField.setVal("");
        }
        return cityLabelAndTextField;
    }

    private LabelAndTextField getZipLabelAndTextField() {
        if (zipLabelAndTextField == null) {
            zipLabelAndTextField = new LabelAndTextField();
            zipLabelAndTextField.setLabel("Code postal");
            zipLabelAndTextField.setVal("");
        }
        return zipLabelAndTextField;
    }

    private LabelAndTextField getTelLabelAndTextField() {
        if (telLabelAndTextField == null) {
            telLabelAndTextField = new LabelAndTextField();
            telLabelAndTextField.setLabel("T\351l");
            telLabelAndTextField.setVal("");
        }
        return telLabelAndTextField;
    }

    private LabelAndTextField getFaxLabelAndTextField() {
        if (faxLabelAndTextField == null) {
            faxLabelAndTextField = new LabelAndTextField();
            faxLabelAndTextField.setLabel("Fax");
            faxLabelAndTextField.setVal("");
        }
        return faxLabelAndTextField;
    }

    private LabelAndTextField getEmailLabelAndTextField() {
        if (emailLabelAndTextField == null) {
            emailLabelAndTextField = new LabelAndTextField();
            emailLabelAndTextField.setLabel("Email");
            emailLabelAndTextField.setVal("");
        }
        return emailLabelAndTextField;
    }

    private JPanel getLoginPanel() {
        if (loginPanel == null) {
            FlowLayout flowLayout2 = new FlowLayout();
            loginPanel = new JPanel();
            loginPanel.setLayout(flowLayout2);
            loginPanel.add(getLoginLabelAndTextField(), null);
            loginPanel.add(getPasswordLabelAndTextField(), null);
            loginPanel.add(getGroupLabelAndComboBox(), null);
            loginPanel.add(getJobLabelAndTextField(), null);
            loginPanel.add(getNumberConnectionLabelAndTextField(), null);
            loginPanel.add(getLastConnectionLabelAndTextField(), null);
            loginPanel.add(getExpiryDateLabelAndDateComboBox(), null);
            loginPanel.add(getJScrollPane(), null);
        }
        return loginPanel;
    }

    private LabelAndTextField getCelLabelAndTextField() {
        if (celLabelAndTextField == null) {
            celLabelAndTextField = new LabelAndTextField();
            celLabelAndTextField.setVal("");
            celLabelAndTextField.setLabel("Portable");
        }
        return celLabelAndTextField;
    }

    private LabelAndTextField getLoginLabelAndTextField() {
        if (loginLabelAndTextField == null) {
            loginLabelAndTextField = new LabelAndTextField();
            loginLabelAndTextField.setLabel("Login");
            loginLabelAndTextField.setVal("");
        }
        return loginLabelAndTextField;
    }

    private LabelAndTextField getPasswordLabelAndTextField() {
        if (passwordLabelAndTextField == null) {
            passwordLabelAndTextField = new LabelAndTextField();
            passwordLabelAndTextField.setLabel("Mot de passe");
            passwordLabelAndTextField.setVal("");
        }
        return passwordLabelAndTextField;
    }

    private LabelAndComboBox getGroupLabelAndComboBox() {
        if (groupLabelAndComboBox == null) {
            groupLabelAndComboBox = new LabelAndComboBox();
            groupLabelAndComboBox.setLabel("Groupe");
        }
        return groupLabelAndComboBox;
    }

    private LabelAndTextField getJobLabelAndTextField() {
        if (jobLabelAndTextField == null) {
            jobLabelAndTextField = new LabelAndTextField();
            jobLabelAndTextField.setLabel("Poste");
            jobLabelAndTextField.setVal("");
        }
        return jobLabelAndTextField;
    }

    private LabelAndTextField getNumberConnectionLabelAndTextField() {
        if (numberConnectionLabelAndTextField == null) {
            numberConnectionLabelAndTextField = new LabelAndTextField();
            numberConnectionLabelAndTextField.setLabel("Nb de connexion");
            numberConnectionLabelAndTextField.setVal("");
            numberConnectionLabelAndTextField.getTextField().setEnabled(false);
        }
        return numberConnectionLabelAndTextField;
    }

    private LabelAndTextField getLastConnectionLabelAndTextField() {
        if (lastConnectionLabelAndTextField == null) {
            lastConnectionLabelAndTextField = new LabelAndTextField();
            lastConnectionLabelAndTextField.setLabel("Derni\350re connexion");
            lastConnectionLabelAndTextField.setVal("");
            lastConnectionLabelAndTextField.getTextField().setEnabled(false);
        }
        return lastConnectionLabelAndTextField;
    }

    private LabelAndDateComboBox getExpiryDateLabelAndDateComboBox() {
        if (expiryDateLabelAndDateComboBox == null) {
            expiryDateLabelAndDateComboBox = new LabelAndDateComboBox();
            expiryDateLabelAndDateComboBox.setLabel("Date d'expiration");
        }
        return expiryDateLabelAndDateComboBox;
    }

    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setHorizontalScrollBarPolicy(31);
            jScrollPane.setViewportView(getMsgTextArea());
            jScrollPane.setPreferredSize(new Dimension(306, 50));
        }
        return jScrollPane;
    }

    private JTextArea getMsgTextArea() {
        if (msgTextArea == null) {
            msgTextArea = new JTextArea();
            msgTextArea.setRows(3);
            msgTextArea.setLineWrap(true);
            msgTextArea.setWrapStyleWord(true);
            msgTextArea.setPreferredSize(new Dimension(286, 50));
            msgTextArea.setToolTipText("Message d'accueil au Login");
        }
        return msgTextArea;
    }

    private TableViewer getLawTableViewer() {
        if (lawTableViewer == null) {
            lawTableViewer = new TableViewer();
        }
        return lawTableViewer;
    }

    public BasicMenu getMenuPanel() {
        return getBasicMenu();
    }

    public IconBar getIconBarPanel() {
        return getIconBar();
    }

    public int getUserListValue() {
        return getUserListLabelAndComboBox().getSelectedIndex();
    }

    public void setUserListValue(int index) {
        getUserListLabelAndComboBox().setSelectedIndex(index);
    }

    public void setUserListValue(String list[]) {
        getUserListLabelAndComboBox().setList(list);
    }

    public JComboBox getUserListComboBox() {
        return getUserListLabelAndComboBox().getComboBox();
    }

    public String getLastnameValue() {
        return getLastnameLabelAndTextField().getVal();
    }

    public void setLastnameValue(String txt) {
        getLastnameLabelAndTextField().setVal(txt);
    }

    public String getFirstnameValue() {
        return getFirstnameLabelAndTextField().getVal();
    }

    public void setFirstnameValue(String txt) {
        getFirstnameLabelAndTextField().setVal(txt);
    }

    public String getAddrLn1Value() {
        return getAddrLn1LabelAndTextField().getVal();
    }

    public void setAddrLn1Value(String txt) {
        getAddrLn1LabelAndTextField().setVal(txt);
    }

    public String getAddrLn2Value() {
        return getAddrLn2LabelAndTextField().getVal();
    }

    public void setAddrLn2Value(String txt) {
        getAddrLn2LabelAndTextField().setVal(txt);
    }

    public String getCityValue() {
        return getCityLabelAndTextField().getVal();
    }

    public void setCityValue(String txt) {
        getCityLabelAndTextField().setVal(txt);
    }

    public String getZipValue() {
        return getZipLabelAndTextField().getVal();
    }

    public void setZipValue(String txt) {
        getZipLabelAndTextField().setVal(txt);
    }

    public String getTelValue() {
        return getTelLabelAndTextField().getVal();
    }

    public void setTelValue(String txt) {
        getTelLabelAndTextField().setVal(txt);
    }

    public String getFaxValue() {
        return getFaxLabelAndTextField().getVal();
    }

    public void setFaxValue(String txt) {
        getFaxLabelAndTextField().setVal(txt);
    }

    public String getEmailValue() {
        return getEmailLabelAndTextField().getVal();
    }

    public void setEmailValue(String txt) {
        getEmailLabelAndTextField().setVal(txt);
    }

    public String getCelValue() {
        return getCelLabelAndTextField().getVal();
    }

    public void setCelValue(String txt) {
        getCelLabelAndTextField().setVal(txt);
    }

    public String getLoginValue() {
        return getLoginLabelAndTextField().getVal();
    }

    public void setLoginValue(String txt) {
        getLoginLabelAndTextField().setVal(txt);
    }

    public String getPasswordValue() {
        return getPasswordLabelAndTextField().getVal();
    }

    public void setPasswordValue(String txt) {
        getPasswordLabelAndTextField().setVal(txt);
    }

    public int getGroupValue() {
        return getGroupLabelAndComboBox().getSelectedIndex();
    }

    public void setGroupValue(int index) {
        getGroupLabelAndComboBox().setSelectedIndex(index);
    }

    public void setGroupListValue(String list[]) {
        getGroupLabelAndComboBox().setList(list);
    }

    public String getJobValue() {
        return getJobLabelAndTextField().getVal();
    }

    public void setJobValue(String txt) {
        getJobLabelAndTextField().setVal(txt);
    }

    public String getNumberConnectionValue() {
        return getNumberConnectionLabelAndTextField().getVal();
    }

    public void setNumberConnectionValue(String txt) {
        getNumberConnectionLabelAndTextField().setVal(txt);
    }

    public String getLastConnectionValue() {
        return getLastConnectionLabelAndTextField().getVal();
    }

    public void setLastConnectionValue(String txt) {
        getLastConnectionLabelAndTextField().setVal(txt);
    }

    public String getExpiryDateValue() {
        return getExpiryDateLabelAndDateComboBox().getDate();
    }

    public void setExpiryDateValue(String txt) {
        getExpiryDateLabelAndDateComboBox().setDate(txt);
    }

    public String getMsgValue() {
        return getMsgTextArea().getText();
    }

    public void setMsgValue(String txt) {
        getMsgTextArea().setText(txt);
    }

    public TableViewer getLawTable() {
        return getLawTableViewer();
    }

    public void cleanField() {
        setMsgValue("");
        setExpiryDateValue("");
        setLastConnectionValue("");
        setNumberConnectionValue("");
        setJobValue("");
        setGroupValue(0);
        setPasswordValue("");
        setLoginValue("");
        setCelValue("");
        setEmailValue("");
        setFaxValue("");
        setTelValue("");
        setZipValue("");
        setCityValue("");
        setAddrLn2Value("");
        setAddrLn1Value("");
        setFirstnameValue("");
        setLastnameValue("");
    }

    public void setEnabledField(boolean b) {
        getMsgTextArea().setEnabled(b);
        getExpiryDateLabelAndDateComboBox().setEnabledDateComboBox(b);
        getJobLabelAndTextField().getTextField().setEditable(b);
        getGroupLabelAndComboBox().getComboBox().setEnabled(b);
        getPasswordLabelAndTextField().getTextField().setEditable(b);
        getLoginLabelAndTextField().getTextField().setEditable(b);
        getCelLabelAndTextField().getTextField().setEditable(b);
        getEmailLabelAndTextField().getTextField().setEditable(b);
        getFaxLabelAndTextField().getTextField().setEditable(b);
        getTelLabelAndTextField().getTextField().setEditable(b);
        getZipLabelAndTextField().getTextField().setEditable(b);
        getCityLabelAndTextField().getTextField().setEditable(b);
        getAddrLn2LabelAndTextField().getTextField().setEditable(b);
        getAddrLn1LabelAndTextField().getTextField().setEditable(b);
        getFirstnameLabelAndTextField().getTextField().setEditable(b);
        getLastnameLabelAndTextField().getTextField().setEditable(b);
    }
    private JPanel jContentPane;
    private BasicMenu basicMenu;
    private IconBar iconBar;
    private JTabbedPane jTabbedPane;
    private JPanel mainPanel;
    private JPanel lawPanel;
    private LabelAndComboBox userListLabelAndComboBox;
    private JPanel mainPanel1;
    private LabelAndTextField lastnameLabelAndTextField;
    private LabelAndTextField firstnameLabelAndTextField;
    private LabelAndTextField addrLn1LabelAndTextField;
    private LabelAndTextField addrLn2LabelAndTextField;
    private LabelAndTextField cityLabelAndTextField;
    private LabelAndTextField zipLabelAndTextField;
    private LabelAndTextField telLabelAndTextField;
    private LabelAndTextField faxLabelAndTextField;
    private LabelAndTextField emailLabelAndTextField;
    private JPanel loginPanel;
    private LabelAndTextField celLabelAndTextField;
    private LabelAndTextField loginLabelAndTextField;
    private LabelAndTextField passwordLabelAndTextField;
    private LabelAndComboBox groupLabelAndComboBox;
    private LabelAndTextField jobLabelAndTextField;
    private LabelAndTextField numberConnectionLabelAndTextField;
    private LabelAndTextField lastConnectionLabelAndTextField;
    private LabelAndDateComboBox expiryDateLabelAndDateComboBox;
    private JTextArea msgTextArea;
    private TableViewer lawTableViewer;
    private JScrollPane jScrollPane;
}
